<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Profile Extends MY_Controller
{
	private $current_session_user;
	private $auth_to_update_student;
	private $link_to_view_fees;
	public function __construct()
	{
		parent::__construct();
		//get acl ROles from config config/acl_config
		$this->config->load('acl_config');
		//secure page for assigned roles only
		$this->page_auth->secure_page($this->config->item('secure_page_profile'));
		// set role that can only update student profile
		$this->auth_to_update_student = $this->config->item('auth_update_student_profile');
		// set role that can only view the fee link
		$this->link_to_view_fees = $this->config->item('auth_link_to_view_fees');
		//get current session user
		$this->current_session_user = strtolower($this->session->userdata('userType'));	
		$this->load->helper('grade');
		$this->_init_pagnate_config();
	}
	
	public function student($id='')
	{	
		$this->load->model('M_enrollees');
		
		if($this->M_enrollees->check_enrollment_id($id))
		{
			$this->view_data['student_found'] = TRUE;
			$this->load->helper('student_photo');

			$this->view_data['authlink'] = $this->authlink->generate_authlink();
			//detect if registrar approved
			if($this->current_session_user == 'registrar')
			{
				$this->view_data['registrar'] = TRUE;
			}else{
				$this->view_data['registrar'] = FALSE;
			}
			
			if($this->M_enrollees->check_waiver($id) == TRUE AND $this->current_session_user == 'registrar'){
				$this->view_data['waiver'] = TRUE;
			}else{
				$this->view_data['waiver'] = FALSE;
			}
			
			if($this->M_enrollees->verify_if_approved_by_registrar($id))
			{	
				$this->view_data['enroll'] = TRUE;
			}else{
				$this->view_data['enroll'] = FALSE;
			}

			//check $id must be int or else redirect home
			$user_student_id = is_numeric($id) ? intval($id) : redirect($this->current_session_user);
			$this->load->model(['M_rooms','M_sections','M_student','M_student_subjects','M_student_grades','M_gperiods','M_levels','M_entrance_test_results']);
			$this->student_links();
			
			$this->view_data['system_message'] = $this->_msg();
			
			//catch post if assign to section is clicked
			if($this->input->post('assign'))
			{
				$this->form_validation->set_rules('section_id', 'Section Assignment', 'required');
				if($this->form_validation->run() == FALSE)
				{
					$this->view_data['system_message'] = validation_errors() == '' ? NULL : $this->_msg('e',validation_errors());
				}else{
					if(in_array($this->current_session_user,$this->auth_to_update_student))
					{
							
							$response = $this->M_enrollees->assign_student_section($this->input->post('enrollment_id'), $this->input->post('section_id'));
										
							if($response == 'SUCCESS')
							{
								$enr_id = $this->input->post('enrollment_id');
								$lvl_id = $this->input->post('stud_level_id');
								$sec_id = $this->input->post('section_id');
								
								//generates student subject from given level
								$this->M_student_subjects->generate_student_subjects($enr_id,$lvl_id);
								//generates student grades from given level,and section and grading period
								$this->M_student_grades->generate_student_grades($enr_id,$sec_id);
								//generates student remarks or narratives
								$this->M_student_grades->generate_remarks($enr_id);
								//generates student attendance
								$this->M_student_attendance->generatestudentattendance($enr_id);
								//generates subject children for card
								$this->M_student_subjects->generate_student_subject_children($enr_id,$lvl_id,$sec_id);
								
								$this->_msg('s','Data was updated.','profile/student/'.$this->input->post('enrollment_id'));
							}else{
								$this->_msg('e','Data was not updated.','profile/student/'.$this->input->post('enrollment_id'));
							}
					}else{
						$this->view_data['system_message'] = $this->_msg('n','You have not been granted update privileges.');
					}
				}
			}
			
			/*
			 * Updates student personal profile
			 */
			if($this->input->post('update'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					
					$profile_data['email'] = $v->email;
					$profile_data['firstname'] = $v->child_fname;
					$profile_data['middlename'] = strtolower($v->child_mname) == 'none' ? NULL : $v->child_mname;
					$profile_data['lastname'] = $v->child_lname;
					$profile_data['nickname'] = $v->child_nickname;
					$profile_data['name_ext'] = $v->child_name_ext;
					$profile_data['gender'] = $v->gender;
					$profile_data['dob'] = DateTime::createFromFormat('m/d/Y',$v->child_bdate)->format('Y-m-d');
					$profile_data['nationality'] = $v->child_nationality;
					$profile_data['pob'] = $v->child_placeofbirth;
					$profile_data['present_address'] = $v->child_city_address;
					$profile_data['contact_no'] = $v->child_telno;
					$profile_data['contact_no'] = $v->mobile_phone;
					$profile_data['religion'] = $v->child_religous;
					$profile_data['living_in_ph_with_father'] = !isset($v->living_in_ph_with_father) ? 'no' : 'yes';
					$profile_data['living_in_ph_with_mother'] = !isset($v->living_in_ph_with_mother) ? 'no' : 'yes';
					$profile_data['living_in_ph_with_step_father'] = !isset($v->living_in_ph_with_step_father) ? 'no' : 'yes';
					$profile_data['living_in_ph_with_step_mother'] = !isset($v->living_in_ph_with_step_mother) ? 'no' : 'yes';
					$profile_data['living_in_ph_with_guardian'] = !isset($v->living_in_ph_with_guardian) ? 'no' : 'yes';
					$profile_data['living_in_ph_with_legal_guardian_name'] = $v->living_in_ph_with_legal_guardian_name;
					$profile_data['living_in_ph_with_legal_guardian_contact_number'] = $v->living_in_ph_with_legal_guardian_contact_number;
					$profile_data['childs_english_reading_writing_level'] = $v->childs_english_reading_writing_level;
					$profile_data['childs_english_verbal_proficiency'] = $v->childs_english_verbal_proficiency;
					$profile_data['language_at_home'] = $v->language_at_home;
					$profile_data['participation_in_advanced_level_classes'] = $v->participation_in_advanced_level_classes;
					$profile_data['remedial_help_in_previous_schools'] = $v->remedial_help_in_previous_schools;
					$profile_data['special_talent_interest_dance'] = !isset($v->special_talent_interest_dance) ? 'no' : 'yes';
					$profile_data['special_talent_interest_drama'] = !isset($v->special_talent_interest_drama) ? 'no' : 'yes';
					$profile_data['special_talent_interest_art'] = !isset($v->special_talent_interest_art) ? 'no' : 'yes';
					$profile_data['special_talent_interest_acomputer'] = !isset($v->special_talent_interest_acomputer) ? 'no' : 'yes';
					$profile_data['special_talent_interest_vocal_chorus'] = !isset($v->special_talent_interest_vocal_chorus) ? 'no' : 'yes';
					$profile_data['special_talent_interest_athletics'] = !isset($v->special_talent_interest_athletics) ? 'no' : 'yes';
					$profile_data['special_talent_interest_athletics_spec'] = $v->special_talent_interest_athletics_spec;
					$profile_data['special_talent_interest_band'] = !isset($v->special_talent_interest_band ) ? 'no' : 'yes';
					$profile_data['special_talent_interest_band_spec'] = $v->special_talent_interest_band_spec;
					$profile_data['special_talent_interest_string'] = !isset($v->special_talent_interest_string) ? 'no' : 'yes';
					$profile_data['special_talent_interest_string_spec'] = $v->special_talent_interest_string_spec;
					$profile_data['dhc_hinder_learning_process'] =$v->hinder_childs_learning;
					$profile_data['leave_school'] =$v->leave_school;
					$profile_data['previous_school'] =$v->previous_school;
					$profile_data['previous_school_address'] =$v->previous_school_address;
					$profile_data['previous_school_grade_1'] =$v->previous_school_grade_1;
					$profile_data['previous_school_name_1'] =$v->previous_school_name_1;
					$profile_data['previous_school_year_1'] =$v->previous_school_year_1;
					$profile_data['previous_school_grade_2'] =$v->previous_school_grade_2;
					$profile_data['previous_school_name_2'] =$v->previous_school_name_2;
					$profile_data['previous_school_year_2'] =$v->previous_school_year_2;
					$profile_data['previous_school_grade_3'] =$v->previous_school_grade_3;
					$profile_data['previous_school_name_3'] =$v->previous_school_name_3;
					$profile_data['previous_school_year_3'] =$v->previous_school_year_3;
					$profile_data['name_of_siblings_and_school_attended'] =$v->name_of_siblings_and_school_attended;
					
					if($this->M_student->update_profile($profile_data, $v->profile_id))
					{
						$this->_msg('s','Personal information was updated.','profile/student/'.$v->enrollment_id);
					}else{
						$this->_msg('e','An error occurred while trying to update student.','profile/student/'.$v->enrollment_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			/*
			 * Updates student family history data
			 */
			
			if($this->input->post('update_parent_legal_information'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					
					$profile_data['fathername'] = $v->father_name;
					$profile_data['father_mname'] = $v->father_mname;
					$profile_data['father_lname'] = $v->father_lname;
					$profile_data['father_nationality'] = $v->father_citizenship;
					$profile_data['father_visa'] = $v->father_visa;
					$profile_data['father_occupation'] =$v->father_occup;
					$profile_data['father_office_num'] =$v->father_office_tel;
					$profile_data['father_contact_no'] =$v->father_contact_no;
					$profile_data['father_contact_no_text'] = !isset($v->father_contact_no_text) ? 'no' : 'yes';
					$profile_data['father_graduate_degree'] =$v->father_graduate_degree;
					$profile_data['father_school'] =$v->father_school;
					$profile_data['father_income_bracket'] =$v->father_income_bracket;
					$profile_data['mothername'] =$v->mother_name;
					$profile_data['mother_mname'] =$v->mother_mname;
					$profile_data['mother_lname'] =$v->mother_lname;
					$profile_data['mother_nationality'] =$v->mother_citizenship;
					$profile_data['mother_visa'] =$v->mother_visa;
					$profile_data['mother_occupation'] =$v->mother_occup;
					$profile_data['mother_office_num'] =$v->mother_office_tel;
					$profile_data['mother_contact_no'] =$v->mother_contact_no;
					$profile_data['mother_contact_no_text'] = !isset($v->mother_contact_no_text) ? 'no' : 'yes';
					$profile_data['mother_graduate_degree'] =$v->mother_graduate_degree;
					$profile_data['mother_school'] =$v->mother_school;
					$profile_data['mother_income_bracket'] =$v->mother_income_bracket;
					$profile_data['step_father_name'] =$v->step_father_name;
					$profile_data['step_father_mname'] = $v->step_father_mname;
					$profile_data['step_father_lname'] = $v->step_father_lname;
					$profile_data['step_father_citizenship'] =$v->step_father_citizenship;
					$profile_data['step_father_visa'] =$v->step_father_visa;
					$profile_data['step_father_occup'] =$v->step_father_occup;
					$profile_data['step_father_office_tel'] =$v->step_father_office_tel;
					$profile_data['step_father_contact_no'] =$v->step_father_contact_no;
					$profile_data['step_father_contact_no_text'] = !isset($v->step_father_contact_no_text) ? 'no' : 'yes';
					$profile_data['step_father_graduate_degree'] =$v->step_father_graduate_degree;
					$profile_data['step_father_school'] =$v->step_father_school;
					$profile_data['step_father_income_bracket'] =$v->step_father_income_bracket;
					$profile_data['step_mother_name'] =$v->step_mother_name;
					$profile_data['step_mother_mname'] = $v->step_mother_mname;
					$profile_data['step_mother_lname'] = $v->step_mother_lname;
					$profile_data['step_mother_citizenship'] =$v->step_mother_citizenship;
					$profile_data['step_mother_visa'] =$v->step_mother_visa;
					$profile_data['step_mother_occup'] =$v->step_mother_occup;
					$profile_data['step_mother_office_tel'] =$v->step_mother_office_tel;
					$profile_data['step_mother_contact_no'] =$v->step_mother_contact_no;
					$profile_data['step_mother_contact_no_text'] = !isset($v->step_mother_contact_no_text) ? 'no' : 'yes';
					$profile_data['step_mother_graduate_degree'] =$v->step_mother_graduate_degree;
					$profile_data['step_mother_school'] =$v->step_mother_school;
					$profile_data['step_mother_income_bracket'] =$v->step_mother_income_bracket;
					$profile_data['guardian_name'] =$v->guardian_name;
					$profile_data['guardian_citizenship'] =$v->guardian_citizenship;
					$profile_data['guardian_visa'] =$v->guardian_visa;
					$profile_data['guardian_occup'] =$v->guardian_occup;
					$profile_data['guardian_office_tel'] =$v->guardian_office_tel;
					$profile_data['guardian_contact_no'] =$v->guardian_contact_no;
					$profile_data['guardian_contact_no_text'] = !isset($v->guardian_contact_no_text) ? 'no' : 'yes';
					$profile_data['emergency_name'] =$v->emergency_name;
					$profile_data['emergency_address'] =$v->emergency_address;
					$profile_data['emergency_office_tel'] =$v->emergency_office_tel;
					$profile_data['emergency_home_tel'] =$v->emergency_home_tel;
					$profile_data['emergency_home_no'] =$v->emergency_home_no;
					$profile_data['failure_to_provide'] = !isset($v->failure_to_provide) ? 'no' : 'yes';
					$profile_data['to_the_best'] = !isset($v->to_the_best) ? 'no' : 'yes';
					
					if($this->M_student->update_profile($profile_data, $v->profile_id))
					{
						$this->_msg('s','Parent legal information was updated.','profile/student/'.$v->enrollment_id);
					}else{
						$this->_msg('e','An error occurred while trying to update parent legal information.','profile/student/'.$v->enrollment_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('update_family_history'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					
					$profile_data['parent_status'] = $v->parent_status;
					$profile_data['parent_status_how_long'] = $v->status_how_long;
					$profile_data['parent_rights'] = $v->right_over_child;
					$profile_data['child_pos'] = $v->position_of_child;
					$profile_data['child_adopted'] = $v->is_child_adopted;
					$profile_data['child_age_adopted'] = $v->age_of_adoption;
					$profile_data['child_aware_adopted'] = $v->child_aware_adopted;
					$profile_data['mother_present_pregnant'] = $v->mother_presently_pregnant;
					$profile_data['mother_due_date'] = $v->mother_pregnancy_due_date;
					$profile_data['family_deaths'] = $v->family_deaths;
					$profile_data['family_deaths_child_relation'] = $v->family_deaths_relation;
					$profile_data['family_accidents'] = $v->family_accidents;
					$profile_data['family_accidents_child_relation'] = $v->family_accidents_relation;
					$profile_data['what'] = $v->what;
					$profile_data['when'] = $v->when;
					$profile_data['sibling_age1'] = $v->siblingage1;
					$sprofile_data['sibling_age2'] = $v->siblingage2;
					$profile_data['sibling_age3'] = $v->siblingage3;
					$profile_data['sibling_age4'] = $v->siblingage4;
					$profile_data['sibling_age5'] = $v->siblingage5;
					$profile_data['sibling_age6'] = $v->siblingage6;
					$profile_data['sibling_fname1'] = $v->siblingfname1;
					$profile_data['sibling_fname2'] = $v->siblingfname2;
					$profile_data['sibling_fname3'] = $v->siblingfname3;
					$profile_data['sibling_fname4'] = $v->siblingfname4;
					$profile_data['sibling_fname5'] = $v->siblingfname5;
					$sprofile_data['sibling_fname6'] = $v->siblingfname6;
					$profile_data['sibling_lname1'] = $v->siblinglname1;
					$profile_data['sibling_lname2'] = $v->siblinglname2;
					$profile_data['sibling_lname3'] = $v->siblinglname3;
					$profile_data['sibling_lname4'] = $v->siblinglname4;
					$profile_data['sibling_lname5'] = $v->siblinglname5;
					$profile_data['sibling_lname6'] = $v->siblinglname6;
					$profile_data['other_household_member1'] = $v->hhmembers1;
					$profile_data['other_household_member2'] = $v->hhmembers2;
					$profile_data['other_household_member3'] = $v->hhmembers3;
					$profile_data['other_household_member4'] = $v->hhmembers4;
					$profile_data['other_household_member5'] = $v->hhmembers5;
					$profile_data['other_household_member6'] = $v->hhmembers6;
					$profile_data['other_household_age1'] = $v->hhmembersage1;
					$profile_data['other_household_age2'] = $v->hhmembersage2;
					$profile_data['other_household_age3'] = $v->hhmembersage3;
					$profile_data['other_household_age4'] = $v->hhmembersage4;
					$profile_data['other_household_age5'] = $v->hhmembersage5;
					$profile_data['other_household_age6'] = $v->hhmembersage6;
					$profile_data['languages_spoken_at_home'] = $v->language_at_home;
					$profile_data['family_activities'] = $v->family_activities;
					$profile_data['family_activities_frequent'] = $v->family_activities_frequent;
					$profile_data['time_spent_on_tv'] = $v->tv_time;
					$profile_data['tv_whom'] = $v->tv_whom;
					$profile_data['time_spent_on_radio'] = $v->radio_time;
					$profile_data['radio_whom'] = $v->radio_whom;
					$profile_data['time_spent_on_pc'] = $v->computergames_time;
					$profile_data['pc_whom'] = $v->computergames_whom;
					$profile_data['responsibility_what'] = $v->child_responsibilities_what;
					$profile_data['child_playgroup'] = $v->child_play_group;
					$profile_data['child_playgroup_frequent'] = $v->child_play_group_frequent;
					$profile_data['child_interest'] = $v->other_interest;

					if($this->M_student->update_profile($profile_data, $v->profile_id))
					{
						$this->_msg('s','Family history information was updated.','profile/student/'.$v->enrollment_id);
					}else{
						$this->_msg('e','An error occurred while trying to update family history.','profile/student/'.$v->enrollment_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('update_developmental_history'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					$profile_data['dhc_pregnancy_length']= $v->length_of_preg;
					$profile_data['dhc_delivery_form']= $v->form_of_del;
					$profile_data['dhc_compications']= $v->complications;
					$profile_data['dhc_sleep_time']= $v->go_to_bed;
					$profile_data['dhc_wakup_time']= $v->get_up_bed;
					$profile_data['dhc_sleeping_disturbance_what']= $v->sleeping_dist;
					$profile_data['dhc_child_own_room']= $v->own_room;
					$profile_data['dhc_room_shares_who']= $v->room_shares;
					$profile_data['dhc_child_wet_bed']= $v->wet_bed;
					$profile_data['dhc_defect_specify']= $v->observable_difficulties;
					$profile_data['dhc_defect_when']= $v->observable_difficulties_since_when;
					$profile_data['dhc_defect_actions']= $v->observable_difficulties_action_taken;
					$profile_data['dhc_speech_problem_what']= $v->speech_problems;
					$profile_data['dhc_speech_problem_when']= $v->speech_problems_since_when;
					$profile_data['dhc_speech_problem_actions']= $v->speech_problems_actions_taken;
					$profile_data['dhc_hearing_last_check']= $v->hearing_last_checked;
					$profile_data['dhc_hearing_problems_what']= $v->hearing_problems;
					$profile_data['dhc_hearing_problems_when']= $v->hearing_problems_since_when;
					$profile_data['dhc_hearing_problem_actions']= $v->hearing_problems_actions_taken;
					$profile_data['dhc_vision_checked']= $v->vision_last_checked;
					$profile_data['dhc_sight_problems_what']= $v->vision_specify;
					$profile_data['dhc_hinder_learning_process']= $v->hinder_childs_learning;

					if($this->M_student->update_profile($profile_data, $v->profile_id))
					{
						$this->_msg('s','Developmental history information was updated.','profile/student/'.$v->enrollment_id);
					}else{
						$this->_msg('e','An error occurred while trying to update developmental history information.','profile/student/'.$v->enrollment_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('update_childhood_experiences'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					
					$profile_data['ce_trauma_exp_what'] = $v->traumatic_experiences;
					$profile_data['ce_trauma_exp_age'] = $v->age_trauma;
					$profile_data['ce_trauma_exp_reaction'] = $v->trauma_reaction;
					$profile_data['ce_trauma_exp_affected'] = $v->how_trauma_affected_child;
					$profile_data['ce_special_fears_what'] = $v->special_fears;
					$profile_data['ce_special_fears_when'] = $v->when_what_triggered_fear;
					$profile_data['ce_special_fears_handle'] = $v->how_do_you_handle;

					if($this->M_student->update_profile($profile_data, $v->profile_id))
					{
						$this->_msg('s','Information on childhood experiences was updated.','profile/student/'.$v->enrollment_id);
					}else{
						$this->_msg('e','An error occurred while trying to update childhood experiences.','profile/student/'.$v->enrollment_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('update_health_history'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					
					$input['hhc_allergies_reaction'] = $data['allergies_reaction'];
					$input['hhc_alergic_med_reaction'] = $data['drug_allergies_reaction'];
					$input['dhc_sight_problems_what'] = $data['eye_problem_spec'];
					$input['dhc_hearing_problems_what'] = $data['ear_problem_spec'];
					$input['hhc_diagnosed_specify'] = $data['major_ailment'];
					$input['hhc_recently_hospitalized'] = $data['recently_hospitalized'];
					$input['hhc_major_injury_specify'] = $data['major_injury'];
					$input['hhc_medication_school_hours'] = $data['medication_child_taking_spec'];
					$input['hhc_asthma_inhaler'] = isset($data['asthma_inhaler']) ? $data['asthma_inhaler'] : 'no';
					$input['hhc_asthma'] = isset($data['asthma']) ? $data['asthma'] : 'no';

					if($this->M_student->update_profile($profile_data, $v->profile_id))
					{
						$this->_msg('s','Health history was successfully updated.','profile/student/'.$v->enrollment_id);
					}else{
						$this->_msg('e','An error occurred while trying to update childhood experiences.','profile/student/'.$v->enrollment_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('update_discipline'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					$profile_data['d_method_of_discipline'] = $v->methods_of_discp;
					$profile_data['d_handles_discipline'] = $v->who_handles_discp_home;
					$profile_data['d_discipline_effective'] = $v->how_effective_discp;
					$profile_data['d_discipline_rod_why'] = $v->rod_discp;
					$profile_data['d_teacher_use_rod_why'] = $v->allow_teacher_use_rod;
					$profile_data['d_suggest_discipline'] = $v->what_form_of_discp_use;
					$profile_data['d_school_help_discipline'] = $v->school_supp_discp;
					$profile_data['d_provide_information'] = $v->other_info_about_child;
					
					if($this->M_student->update_profile($profile_data, $v->profile_id))
					{
						$this->_msg('s','Information about discipline was successfully updated.','profile/student/'.$v->enrollment_id);
					}else{
						$this->_msg('e','An error occurred while trying to update discipline.','profile/student/'.$v->enrollment_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('update_authorization'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					$profile_data['auth_firstaid'] = $v->authfirst_aid;
					$profile_data['auth_emergency_care'] = $v->auth_emergency;
					$profile_data['auth_emergency_care_hospital'] = $v->auth_emergency_nearest_hosp;
					$profile_data['auth_oral_non_presc'] = $v->auth_oral_non_presc;
					$profile_data['first_permission'] = isset($v->first_permission) ? 'yes' : 'no';
					$profile_data['second_permission'] = isset($v->second_permission) ? 'yes' : 'no';
					$profile_data['third_permission'] = isset($v->third_permission) ? 'yes' : 'no';
					
					if($this->M_student->update_profile($profile_data, $v->profile_id))
					{
						$this->_msg('s','Information about authorization was successfully updated.','profile/student/'.$v->enrollment_id);
					}else{
						$this->_msg('e','An error occurred while trying to update authorization.','profile/student/'.$v->enrollment_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('checklist_form'))
			{	
				$this->load->helper('misc');
				$post = (object)$this->input->post();
				unset($post->checklist_form);
				unset($post->api_loc);
				unset($post->form_id);
				
				$insert['birthcertificate'] = isset($post->birthcertificate) ? 1 : 0;
				$insert['passport'] = isset($post->passport) ? 1 : 0;
				$insert['immunizationrecord'] = isset($post->immunizationrecord) ? 1 : 0;
				$insert['medicalcertificate'] = isset($post->medicalcertificate)? 1 : 0;
				$insert['idpicture2x2'] = isset($post->idpicture2x2) ? 1 : 0;
				$insert['idpicture1x1'] = isset($post->idpicture1x1) ? 1 : 0;
				$insert['eentcertificate'] = isset($post->eentcertificate) ? 1 : 0;
				$insert['entranceexam'] = isset($post->entranceexam) ? 1 : 0;
				$insert['form137a'] = isset($post->form137a) ? 1 : 0;
				$insert['reccomendationform'] = isset($post->reccomendationform) ? 1 : 0;
				$insert['int_specialpermit'] = isset($post->int_specialpermit) ? 1 : 0;
				$insert['int_acr'] = isset($post->int_acr)? 1 : 0;
				$insert['int_bidcertificate'] = isset($post->int_bidcertificate) ? 1 : 0;
				$insert['int_icr'] =isset( $post->int_icr) ? 1 : 0;
				$insert['int_parentvisa'] = isset($post->int_parentvisa) ? 1 : 0;
				
				if($this->input->post('form_id') == 'update_checklist')
				{
					if($this->M_student->checklist($insert,'update',$id))
					{
						$this->_msg('s','Student list of requirements has been successfully updated.','profile/student/'.$id);
					}else{
						$this->_msg('e','Unable to update student list of requirements.','profile/student/'.$id);
					}
				}else{
					$insert['e_id'] = $id;
				
					if($this->M_student->checklist($insert,'insert'))
					{
						$this->_msg('s','Student list of requirements has been successfully updated.','profile/student/'.$id);
					}else{
						$this->_msg('e','Unable to update student list of requirements.','profile/student/'.$id);
					}
				}
			}
			
			/*
			 * Updates student entrance test result
			 */
			if($this->input->post('insert_entrance_test_result'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					$profile_data['e_id'] = $v->e_id;
					$profile_data['reading_number_right'] = $v->reading_number_right;
					$profile_data['reading_scaled_score'] = $v->reading_scaled_score;
					$profile_data['reading_grade_equivalent'] = $v->reading_grade_equivalent;
					$profile_data['reading_percentile_rank'] = $v->reading_percentile_rank;
					$profile_data['reading_stanine'] = $v->reading_stanine;
					$profile_data['reading_instructional_level'] = $v->reading_instructional_level;
					$profile_data['math_number_right'] = $v->math_number_right;
					$profile_data['math_scaled_score'] = $v->math_scaled_score;
					$profile_data['math_grade_equivalent'] = $v->math_grade_equivalent;
					$profile_data['math_percentile_rank'] = $v->math_percentile_rank;
					$profile_data['math_stanine'] = $v->reading_stanine;
					$profile_data['language_number_right'] = $v->language_number_right;
					$profile_data['language_scaled_score'] = $v->language_scaled_score;
					$profile_data['language_grade_equivalent'] = $v->language_grade_equivalent;
					$profile_data['language_percentile_rank'] = $v->language_percentile_rank;
					$profile_data['language_stanine'] = $v->language_stanine;
					$profile_data['basic_battery_number_right'] = $v->basic_battery_number_right;
					$profile_data['basic_battery_scaled_score'] = $v->basic_battery_scaled_score;
					$profile_data['basic_battery_grade_equivalent'] = $v->basic_battery_grade_equivalent;
					$profile_data['basic_battery_percentile_rank'] = $v->basic_battery_percentile_rank;
					$profile_data['basic_battery_stanine'] = $v->basic_battery_stanine;
					$profile_data['esl'] = $v->esl;
					$profile_data['summer_school'] = $v->summer_school;
					$profile_data['star_program'] = $v->star_program;
					$profile_data['duration'] = $v->duration;
					$profile_data['retain_level'] = $v->retain_level;
					
					if($this->M_entrance_test_results->insert_entrance_test_result($profile_data))
					{
						$this->_msg('s','Information about student entrance test result was successfully updated.','profile/student/'.$v->e_id);
					}else{
						$this->_msg('e','An error occurred while trying to update entrance test results.','profile/student/'.$v->e_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('update_entrance_test_result'))
			{
				if(in_array($this->current_session_user,$this->auth_to_update_student))
				{
					$v = (object)$this->input->post();
					//$profile_data['e_id'] = $v->e_id;
					$profile_data['reading_number_right'] = $v->reading_number_right;
					$profile_data['reading_scaled_score'] = $v->reading_scaled_score;
					$profile_data['reading_grade_equivalent'] = $v->reading_grade_equivalent;
					$profile_data['reading_percentile_rank'] = $v->reading_percentile_rank;
					$profile_data['reading_stanine'] = $v->reading_stanine;
					$profile_data['reading_instructional_level'] = $v->reading_instructional_level;
					$profile_data['math_number_right'] = $v->math_number_right;
					$profile_data['math_scaled_score'] = $v->math_scaled_score;
					$profile_data['math_grade_equivalent'] = $v->math_grade_equivalent;
					$profile_data['math_percentile_rank'] = $v->math_percentile_rank;
					$profile_data['math_stanine'] = $v->reading_stanine;
					$profile_data['language_number_right'] = $v->language_number_right;
					$profile_data['language_scaled_score'] = $v->language_scaled_score;
					$profile_data['language_grade_equivalent'] = $v->language_grade_equivalent;
					$profile_data['language_percentile_rank'] = $v->language_percentile_rank;
					$profile_data['language_stanine'] = $v->language_stanine;
					$profile_data['basic_battery_number_right'] = $v->basic_battery_number_right;
					$profile_data['basic_battery_scaled_score'] = $v->basic_battery_scaled_score;
					$profile_data['basic_battery_grade_equivalent'] = $v->basic_battery_grade_equivalent;
					$profile_data['basic_battery_percentile_rank'] = $v->basic_battery_percentile_rank;
					$profile_data['basic_battery_stanine'] = $v->basic_battery_stanine;
					$profile_data['esl'] = $v->esl;
					$profile_data['summer_school'] = $v->summer_school;
					$profile_data['star_program'] = $v->star_program;
					$profile_data['duration'] = $v->duration;
					$profile_data['retain_level'] = $v->retain_level;
					
					if($this->M_entrance_test_results->update_entrance_test_result($v->e_id,$profile_data))
					{
						$this->_msg('s','Information about student entrance test result was successfully updated.','profile/student/'.$v->e_id);
					}else{
						$this->_msg('e','An error occurred while trying to update entrance test result.','profile/student/'.$v->e_id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted privileges to update this data.');
				}
			}
			
			if($this->input->post('edit_grade_level'))
			{
				// if(in_array($this->current_session_user,$this->auth_to_update_student))
				if(in_array($this->current_session_user,['registrar','cashier','finance','encoder']))
				{
					$d= (object)$this->input->post();
					
					//change student grade level
					$result = $this->M_student->change_student_grade_level($id,$d->grade_level_set);
					if($result->stat == TRUE)
					{/*
						$this->load->model('M_fees','mfees');
						//recompute student fees (misc,tuit,cca)
						if($this->mfees->recompute_student_fees($id))
						{
							$this->load->model('M_scholarships','ms');
							//recompute payment plan
							$recompute_payment_plan = $this->mfees->recompute_payment_plan($id);
							//add scholarships if available
							$this->ms->readd_scholarships($id);
							//add deductions if available
							$this->ms->readd_deductions($id);
							
							if($recompute_payment_plan == true)
							{
								$this->_msg('s','Successfully Updated Student Grade Level and recalculated Fees.','profile/student/'.$id);
							}else{
								$this->_msg('e','Unable to apply student fees.','profile/student/'.$id);
							}
							
						}else{
							$this->_msg('e','Unable to apply student fees.','profile/student/'.$id);
						}*/
						$this->_msg('s','Successfully Updated Student Grade Level.','profile/student/'.$id);
					}else{
						$this->_msg('s',$result->log,'profile/student/'.$id);
					}
				}else{
					$this->view_data['system_message'] = $this->_msg('n','You have not been granted Privileges to update This data');
				}
			}
					
			$this->view_data['user_type'] = $this->session->userdata('userType');
			$this->view_data['level_dropdown'] = $this->M_levels->get_all_levels_array();
			$this->view_data['student'] = $student = $this->M_student->get_student($id);
			$this->view_data['sections'] = $this->M_sections->get_section_by_grade_level_array($this->view_data['student']->level_id);
			$this->view_data['enrollment'] = $this->M_enrollees->get_section_by_profile($id);
			$this->view_data['grading_periods'] = $this->M_gperiods->get_gperiods();
			$this->view_data['student_subjects'] = $this->M_student_subjects->get_all_by_enrollment_id($id);
			$this->view_data['student_grades'] = $student_grades = $this->M_student_grades->grouped_subject_by_enrollment_id($id);
			$this->view_data['file_checklist'] = $this->M_student->check_for_requirements($id);
			$this->view_data['eid_for_url'] = $this->hs->encrypt(intval($id));
			$this->view_data['blocks'] = $this->M_sections->get_block_by_grade_level($student->level_id);
			$this->view_data['entrance_test_result'] = $this->M_entrance_test_results->get_entrance_test_result($id);
			
			if(!(empty($student_grades)))
			{
				$this->view_data['grades'] = $this->_loop_throught_grades($student_grades, $id);
			}
			
		}else{
			show_error('Sorry but unable to fetch data for student ID. Student ID is invalid.',404);
		}
	}
	
/* ========================================= */	
	function student_schedule($id='')
	{
		$this->load->model('M_enrollees');
		if($this->M_enrollees->check_enrollment_id($id))
		{
			$this->load->model('M_student_grades');
			$this->load->model('M_gperiods');
			$this->load->model('M_levels');
			
			$this->load->model('M_student');
			$this->load->model('M_student_subjects');
			$this->view_data['enrollee_data'] = $this->M_enrollees->get_enrollee_prof($id);
			$this->view_data['student'] = $p = $this->M_student->get_student($id);
			$this->view_data['enrollment']= $this->M_enrollees->get_section_by_profile($id);
			$this->view_data['student_subjects'] = $this->M_student_subjects->get_all_by_enrollment_id($id);
			$this->student_links();
		}else{
			show_error('Sorry but unable to fetch data for student ID, student ID is invalid',404);
		}
	}
/* ========================================= */
	function student_grade($id='')
	{
		if(in_array($this->session_user,$this->config->item('view_subject_grade')))
		{
			$this->load->model('M_student_grades');
			$this->load->model('M_gperiods');
			$this->load->model('M_enrollees');
			$this->load->model('M_student');
			$this->view_data['enrollee_data'] = $this->M_enrollees->get_enrollee_prof($id);
			$this->view_data['student'] = $this->M_student->get_student($id);
			$this->view_data['enrollment']= $this->M_enrollees->get_section_by_profile($id);
			$this->view_data['grading_periods'] = $this->M_gperiods->get_gperiods();
			$this->view_data['student_grades'] = $student_grades = $this->M_student_grades->grouped_subject_by_enrollment_id($id);
			
			$this->student_links();
		
			if(!(empty($student_grades)))
			{
				$this->view_data['grades'] = $this->_loop_throught_grades($student_grades, $id);
			}
		}else{
			redirect($this->session_user);
		}
	}
	
	function _loop_throught_grades($student_grades, $enrollment_id)
	{
		foreach($student_grades as $row)
		{
		  $result = $this->M_student_grades->get_all_by_enrollment_id($enrollment_id);
		}
		return $result;
	}
	
	
	
/* ========================================= */

	function edit_student_grade($id)
	{		
		if(in_array($this->session_user,$this->config->item('view_subject_grade')))
		{
			$id = is_numeric($id) ? intval($id) : redirect($this->current_session_user);
			$this->load->Model('M_student_grades');
			$this->load->Model('M_enrollees');
			$this->view_data['student_grade'] = $student_grade = $this->M_student_grades->get($id);
			$this->view_data['enrollee_data'] = $this->M_enrollees->get_enrollee_prof($id);
			$this->view_data['grade_id'] = $id;
			$this->M_enrollees->get($student_grade->enrollment_id);
			
			$this->form_validation->set_rules('value','Value','required');
			
			if($this->input->post('save'))
			{
			$this->form_validation->set_rules('value','Value','required');
			
			if($this->form_validation->run() == FALSE)
			{
				$this->_msg('e',validation_errors(),'profile/edit_student_grade/'.$this->input->post('id'));
			}
			else{
				$data['value'] = $this->input->post('value');
				$data_id= $this->input->post('id');
				$data['enrollment_id'] = $this->input->post('enrollment_id');
				
				if($this->M_student_grades->update($data_id,$data))
				{
					$this->view_data['system_message'] = $this->_msg('s','Student grade edited successfully');
				}else
				{
					$this->view_data['system_message'] = $this->_msg('e','Cannot update this subject grade, please try again later');
				}
			}
			}
		}else{
			redirect($this->session_user);
		}
	}
	
/* ========================================= */
		function student_links()
		{
			//view fees link
			if(in_array($this->current_session_user,$this->link_to_view_fees))
			{
				$this->view_data['finance_link'] = function($p_id,$e_id){return '<li><a href="'.site_url('fees/view_fees/'.$p_id.'/'.$e_id).'" class="add">View Financial Record</a></li>';};
			}else{
				$this->view_data['finance_link'] = function($a,$b){return NULL;};
			}
			
			if($this->session_user == 'registrar')
			{
				$this->view_data['registrar_link'] = function($e_id){return '<li><a href="#" class="add">Permanent Record</a>
														<a href="#" class="add">Account Status</a></li><li><a href="#" class="add">Certificates</a></li>';};
			}else{
				$this->view_data['registrar_link'] = function($e_id){return NULL;};
			}
			
			if(in_array($this->session_user,$this->config->item('view_subject_grade')))
			{
				$this->view_data['grade_link'] = function($p_id){return '<li><a href="'.site_url('profile/student_grade/'.$p_id).'" class="add">View Grades</a></li>';};
			}else{
				$this->view_data['grade_link'] = function($p_id){return NULL;};
			}
			
			$this->view_data['schedule_link'] = function($p_id){return '<li><a href="'.site_url('profile/student_schedule/'.$p_id).'" class="add">View Schedule</a></li>';};
			$this->view_data['profile_link'] = function($p_id){return '<li><a href="'.site_url('profile/student/'.$p_id).'" class="add">View Profile</a></li>';};
			$this->view_data['attendance_link'] = function($p_id){
			return '<li><a href="'.site_url('profile/student_attendance/'.$p_id).'" class="add">View Attendance</a></li>';};
		}
		
		/* ========================================= */

	function student_attendance($id = '', $month_year = '')
	{
		$this->load->model('M_profile');
		$this->load->model('M_student');
		$this->load->model('M_attendance');
		
		if($month_year == '')
		{
			$stud_att = $this->M_attendance->student_attendance($id);
			$stud_totals = $this->M_attendance->get_attendance_totals($id);
			if($stud_att !== FALSE)
			{
				$this->view_data['student_att'] = $stud_att;
				$this->view_data['student_totals'] = $stud_totals;
			}
		}else
		{
			$stud_att = $this->M_attendance->student_attendance_by_month($id, $month_year);
			$stud_totals = $this->M_attendance->get_attendance_totals_by_month($id, $month_year);
			if($stud_att !== FALSE)
			{
				$this->view_data['per_month'] = TRUE;
				$this->view_data['student_att'] = $stud_att;
				$this->view_data['student_totals'] = $stud_totals;
			}
		}
		
		
		$this->view_data['student'] = $this->M_student->get_student($id);
		$this->student_links();
	}
	
	private function _time_format($time)
	{
		if($time == NULL)
		{
			return NULL;
		}else{
			return DateTime::createFromFormat('m/d/Y',$time)->format('Y-m-d');
		}
	}
	
	public function deleted_enrollee($id='')
	{
		$this->load->model('M_enrollees');
		
		if($this->M_enrollees->check_deleted_id($id)){
			$this->view_data['student_found'] = TRUE;
			$this->load->helper('student_photo');

			$this->view_data['authlink'] = $this->authlink->generate_authlink();
			
			//detect whether student is verified by the registrar or , verified enrollee
			if($this->current_session_user == 'registrar')
			{
				$this->view_data['registrar'] = TRUE;
			}else{
				$this->view_data['registrar'] = FALSE;
			}
			
			//check $id must be int or else redirect home
			$user_student_id = is_numeric($id) ? intval($id) : redirect($this->current_session_user);
			$this->load->model(['M_rooms','M_sections','M_student','M_student_subjects','M_student_attendance','M_student_grades','M_gperiods','M_levels']);
			$this->student_links();
			
			$this->view_data['user_type'] = $this->session->userdata('userType');
			$this->view_data['level_dropdown'] = $this->M_levels->get_all_levels_array();
			$this->view_data['student'] = $student = $this->M_student->get_deleted($id);
			//$this->view_data['sections'] = $this->M_sections->get_section_by_grade_level_and_block_array($id,$student->level_id);
			//$this->view_data['enrollment'] = $this->M_enrollees->get_section_by_profile($id);
			//$this->view_data['grading_periods'] = $this->M_gperiods->get_gperiods();
			//$this->view_data['student_subjects'] = $this->M_student_subjects->get_all_by_enrollment_id($id);
			//$this->view_data['student_grades'] = $student_grades = $this->M_student_grades->grouped_subject_by_enrollment_id($id);
			//$this->view_data['file_checklist'] = $this->M_student->check_for_requirements($student->idno);
			$this->view_data['eid_for_url'] = $this->hs->encrypt(intval($id));
			//$this->view_data['blocks'] = $this->M_sections->get_block_by_grade_level($student->level_id);
			$this->view_data['enrollment_id'] = $id;
		}else{
			$this->view_data['student_found'] = FALSE;
			$this->view_data['enrollment_id'] = 0;
		}
		
		$this->view_data['system_message'] = $this->_msg();
	}
	
	/**
	 * Parent Request for updating student profile information
	 */
	public function profile_update_request_by_parent($page = 0)
	{
		//PAGINATION
		$this->view_data['system_message'] = $this->session->flashdata('system_message');
		$this->view_data['search_type'] = 'official';
		
		$filter = false;
		$like = false;
		$order_by = false;
		
		$filter['enrollments.e_ay_id'] = $this->current_school_year;
		$filter['parent_profile_updates.status'] = "PENDING";
		
		if($this->input->get('search_request'))
		{	
			if(isset($_GET['keyword']) && trim($_GET['keyword']) != ''){
				
				if(isset($_GET['search_by']) && trim($_GET['search_by']) != ''){

					$keyword = $this->input->get('keyword');
					$search_by = $this->input->get('search_by');

					if($search_by == "created"){
						$filter['DATE(parent_profile_updates.created)'] = DateTime::createFromFormat('m-d-Y', $keyword)->format('Y-m-d');
					}elseif($search_by == "fullname"){
						$like["CONCAT_WS('',profiles.lastname,', ',profiles.firstname,' ',profiles.middlename)"] = $keyword;
					}else{
						$like[$search_by] = $keyword;
					}
				}
			}
			
			if(isset($_GET['status'])){
				$filter['parent_profile_updates.status'] = $_GET['status'];
				if(trim($_GET['status']) == ''){
					unset($filter['parent_profile_updates.status']);
				}
			}
		}
		
		//CONFIGURATION
		$get['fields'] = array(
				"CONCAT_WS('',profiles.lastname,', ',profiles.firstname,' ',profiles.middlename) AS fullname",
				"levels.level_desc",
				"enrollments.e_student_id AS idno",
				"enrollments.e_id AS enrollment_id",
				"parent_profile_updates.id",
				"parent_profile_updates.created",
				"parent_profile_updates.status",
				"parent_profile_updates.status_by",
				"parent_profile_updates.status_date",
				"parent_profile_updates.reason",
				"parent_profile_updates.guardian_user_id",
				"users.`username` AS guardian"
		);
		
		$get['where'] = $filter;
		$get['like'] = $like;
		// vd($filter);
		$get['join'] = array(
			
			1 => array(
				"table" => "profiles",
				"on"	=> "profiles.profile_id = parent_profile_updates.profile_id",
				"type"  => "LEFT"
			),
			2 => array(
				"table" => "enrollments",
				"on"	=> "enrollments.e_id = parent_profile_updates.enrollment_id",
				"type"  => "LEFT"
			),
			3 => array(
				"table" => "levels",
				"on"	=> "levels.level_id = enrollments.e_grade_level",
				"type"  => "LEFT"
			),
			4 => array(
				"table" => "users",
				"on"	=> "users.id = parent_profile_updates.guardian_user_id",
				"type"  => "LEFT"
			)
		);
		$get['order'] = "parent_profile_updates.created";
		$get['all'] = true; //GET ALL EXCLUDE LIMIT
		$get['count'] = true; //RETURN COUNT NOT ROW
		$get['array'] = false; //RETURN OBJECT NOT ARRAY
		$get['single'] = false; //RETURN ALL NOT SINGLE
		
	
		$this->load->library("pagination");
		$this->pagnate_config["base_url"] = base_url() ."profile/profile_update_request_by_parent";
		$suffix = '?'.http_build_query($_GET, '', "&");
		$suffix = str_replace("&submit=Search", "", $suffix);
		$this->pagnate_config['suffix'] = $suffix;
		$this->pagnate_config['first_url'] = $this->pagnate_config['base_url'].$this->pagnate_config['suffix']; 
		
		$this->load->model('M_parent_profile_updates','m_ppu');
		$this->view_data['total_rows'] = $this->pagnate_config["total_rows"] = $this->m_ppu->get_record(false, $get);
		
		$this->pagnate_config["per_page"] = 30;
		$this->pagnate_config['num_links'] = 10;
		$this->pagnate_config["uri_segment"] = 3;
		$this->pagination->initialize($this->pagnate_config);
		
		//FOR PAGINATION
		$get['all'] = false;
		$get['count'] = false;
		
		$get['start'] = $page;
		$get['limit'] = $this->pagnate_config['per_page'];
		
		$this->view_data['search'] = $search = $this->m_ppu->get_record(false, $get);
		$this->view_data['links'] = $this->pagination->create_links();

		$this->view_data['search_by'] = array(
				'created' => 'Request Date (mm-dd-yy)',
				'users.username' => 'Requestor',
				'enrollments.e_student_id' => 'Student ID No.',
				'fullname' => 'Student Name',
				'levels.level_desc' => 'Grade Level'
			);

		$this->view_data['status'] = array(
				'' => "ALL",
				'APPROVE' => "APPROVE",
				'PENDING' => "PENDING",
				'DENIED' => "DENIED",
				'SELECTIVE-APPROVE' => "SELECTIVE APPROVE",
			);
	}
	
	public function view_parent_request($hash="")
	{
		$x = $this->hs->decrypt($hash);
		if($x)
		{	
			$this->load->model('M_parent_profile_updates','m_ppu');
			$this->load->model(['M_sections','M_levels','M_enrollees','M_gperiods']);
			$this->load->helper('parent');

			$req_id = $x[0];

			$this->view_data['system_message'] = $this->_msg();
			$this->view_data['request'] = $request = $this->m_ppu->get_student($req_id); if(!$request){ show_404(); }
			$this->view_data['student'] = $student = $this->m_ppu->get_student($req_id);

			$this->view_data['user_type'] = $this->session->userdata('userType');
			$this->view_data['level_dropdown'] = $this->M_levels->get_all_levels_array();
			$this->view_data['sections'] = $this->M_sections->get_section_by_grade_level_and_block_array($student->enrollment_id,$student->level_id);
			$this->view_data['enrollment'] = $this->M_enrollees->get_section_by_profile($student->enrollment_id);
			$this->view_data['grading_periods'] = $this->M_gperiods->get_gperiods();
			$this->view_data['blocks'] = $this->M_sections->get_block_by_grade_level($student->level_id);
			$this->view_data['req_id'] = $req_id;
			$student->edit = 0;

			if($this->input->post()){

				if($this->input->post('col')){

					$rs = $this->m_ppu->save_parent_request($this->input->post(), $req_id);

					if($rs->status){
						$this->_msg('s', $rs->msg, current_url());
					}else{
						$this->_msg('e', $rs->msg, current_url());
					}

				}else{
					$this->_msg('e','Transaction failed. No items selected/checked.', current_url());
				}
			}

		}else{ show_404(); }
	}
}
